<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="./mdui.min.css" rel="stylesheet">
    <script src="./mdui.global.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #212121;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100vh;
        }

        .box {
            width: 500px;
            height: 250px;
            background-color: #585858;
            border-radius: 20px;
            padding: 20px;
        }

        h1 {
            color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="box">
        <br>
        <h1 style="text-align: center;margin-bottom: 50px;">如何称呼您</h1>

        <mdui-text-field variant="outlined" label="请输入姓名" style="margin-bottom: 20px;" id="in"></mdui-text-field>
        <mdui-button full-width onclick="user()">开始聊天</mdui-button>
    </div>
</body>
<script>
    function user() {
        let name = document.getElementById("in").value
        if (name == "") {
            alert("请输入姓名")
            return;
        }
        fetch("/new?username=" + name).then(res => { res.json() }).then(res => {
            localStorage.setItem("user", name)
            location.href = "/index.html"
        }).catch(err => {
            console.log(err)
            alert("服务器错误")
        })

    }
</script>

</html>